package com.jingtai.platform.controller.admin;

import com.jingtai.core.entity.BaseEntity;
import com.jingtai.core.entity.admin.Menu;
import com.jingtai.core.entity.admin.PlatformAccount;
import com.jingtai.platform.service.admin.MenuService;
import com.jingtai.platform.util.ResultUtil;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.jingtai.validate.swagger.CApiParam;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 菜单表
 *
 * @author sunlaiqian
 * @date 2020-12-02 18:31:33
 */
@Validated
@RestController
@RequestMapping("/platform/menu")
@Api(tags = "菜单表")
public class MenuController{

    @Autowired
    private MenuService menuService;


    @ApiOperation("菜单表列表查询")
    @GetMapping("/list")
    public ResultUtil aopMenuList(@CApiParam(name = "page",value = "页数",required = true,cNotEmpty = true,cIntMin = 1) @RequestParam("page") Integer page,
                              @CApiParam(name = "limit",value = "每页个数",required = true,cNotEmpty = true,cIntMin = 1) @RequestParam("limit") Integer limit,
                              @CApiParam(name = "conditions",value = "查询条件",required = false) @RequestParam("conditions") String conditions){
        return menuService.Menulist(page, limit, conditions);
    }


    @ApiOperation("根据ID查询menu实体")
    @GetMapping("/getMenuById")
    public ResultUtil GetMenuById(@CApiParam(name = "id",value = "menu实体ID",required = true,cNotEmpty = true) @RequestParam("id") Long id){
        return menuService.getMenuById(id);
    }


    @ApiOperation("新增menu实体")
    @PostMapping("/add")
    @ApiOperationSupport(ignoreParameters = {"menu.id","menu.createTime","menu.updateTime","menu.deleteFlag"})
    public ResultUtil aopAddMenu(@RequestBody @Validated({BaseEntity.Create.class}) Menu menu){
        return menuService.addMenu(menu);
    }

    @ApiOperation("编辑menu实体")
    @PostMapping("/edit")
    @ApiOperationSupport(ignoreParameters = {"menu.createTime","menu.updateTime","menu.deleteFlag"})
    public ResultUtil aopEditMenu(@RequestBody @Validated({BaseEntity.Update.class}) Menu menu){
        return menuService.editMenu(menu);
    }

    @ApiOperation("根据ID删除menu实体")
    @GetMapping("/delMenuById")
    public ResultUtil aopDelMenuById(@CApiParam(name = "id",value = "menu实体ID",required = true,cNotEmpty = true) @RequestParam("id") Long id){
        return menuService.delMenuById(id);
    }

    @ApiOperation("根据平台账户ID查询所拥有权限的菜单")
    @GetMapping("/selectMenu")
    public ResultUtil aopSelectMenu(@CApiParam(name = "id",value = "平台账户实体ID",required = true,cNotEmpty = true) @RequestParam("id") Long id) {
        return menuService.selectMenu(id);
    }

    @ApiOperation("查询所有可用的一级菜单")
    @GetMapping("/selectMenuOfOne")
    public ResultUtil aopSelectMenuOfOne() {
        return menuService.selectMenuOfOne();
    }

    @ApiOperation("查询所有可用的一级菜单以及二级菜单")
    @GetMapping("/selectLevelIsOneAndTwo")
    public ResultUtil aopSelectLevelIsOneAndTwo() {
        return menuService.selectLevelIsOneAndTwo();
    }

}






